<template>
    <div class="confirm">
        <div class="confirm_title">
            <span><i class="glyphicon glyphicon-triangle-right"> </i>  购买确认</span>
            <!--<span>继续添加商品</span>-->
            <span @click="goBack">返回</span>
        </div>
        <hr>
        <div class="goodsList" v-for="data in goodsInfo.orderGoods">
            <div class="goodsLeft">
                <img :src="url(data.goods.thumb.url, '250x250')" alt="">
            </div>
            <div class="goodsRight">
                <div class="goodsName">{{data.goods.name}} {{data.goodsAttr?'(规格：'+data.goodsAttr.name+')':''}}</div>
                <div class="goodsInfo">
                    <p>价格和数量<span>{{data.number}}*￥{{data.goods.price}}</span></p>
                    <p>简介<span>{{data.goods.brief}}</span></p>
                    <p>发货<span>1-2周 免费送货</span></p>
                    <!--<p>数量<span>-->
                        <!--<div class="input-group">-->
                            <!--<span class="input-group-addon glyphicon glyphicon-minus input-group-addon-left"></span>-->
                            <!--<input type="text" class="form-control" style="padding: 0 30px; width: 100px;text-align: center">-->
                            <!--<span class="input-group-addon glyphicon glyphicon-plus"></span>-->
                        <!--</div>-->

                    <!--</span></p>-->
                </div>
            </div>
            <hr style="clear: both;">
        </div>
        <div class="userInfo">
            <p>联系方式 <span>{{address?address.consignee:'请选择地址'}} {{address?address.mobile:''}}</span></p>
            <p>配送地址 <span>
                {{address?(address.provinceRegion.name+address.cityRegion.name+address.districtRegion.name+address.address):'请选择地址'}}
            </span></p>
            <p class="edit_address" @click="editAddress()"><span>选择地址</span><span>手动添加地址</span></p>
            <p>备注 <span><input v-model="post_text"></span></p>
            <button class="btn btn-primary" @click="pay">在线支付</button>
        </div>
        <div class="bottom_prompt">
            <p>结账时会显示你所在地区的送货详情。</p>
            <p>获得购买帮助，立即聊天或致电 0560-3030303。</p>
        </div>
    </div>
</template>
<script>
require('./confirm.css');
var urlParm=require('./lib/urlParm');
module.exports={
    data:function () {
        return{
            id:null,
            goodsInfo:{},
            address:null,
            post_text:'',//备注
        }
    },
    methods:{
        url:JxSdk.img.getUrl,
        goBack:function () {
            this.$router.back();
        },
        editAddress:function () {
            var _self = this;
            JxSdk.user.address().then(function (data) {
                _self.address = data;
            });
        },
        pay:function () {
            var _self = this;
            if(!this.address){
                alert('请选择地址');
                return
            }
            var data = [{
                id:this.id,
                'address_id':this.address.id,
                'post_text':this.post_text,
            }];
            JxSdk.orderPre.changeInfo(data).then(function () {
                var ary = [_self.id];
                JxSdk.orderPre.pay(ary).then(function (data) {
                    _self.$router.push('/order');
                });
            });

        }
    },
    mounted:function () {
        var str=location.href;
        var url=urlParm.default();
        var _self = this;
        this.id=url.id;
        if(url.id){
            JxSdk.ready(function () {
                JxSdk.orderPre.get(url.id).then(function (data) {
                    _self.goodsInfo = data.orderPre;
                });
            })
        }
    }
}
</script>